﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class Form2 : Form
    {
        public Form2(string str)
        {
            InitializeComponent();
            toolStripStatusLabel5.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//当前时间
            timer1.Start();//时间
            Table();
            if (str == "教师")//权限
            {
                toolStripButton1.Enabled = false;
            toolStripButton2.Enabled = false;
            toolStripButton3.Enabled = false;
            信息管理ToolStripMenuItem.Enabled = false;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)//当前时间设置
        {
            toolStripStatusLabel5.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void Form2_FormClosed(object sender, FormClosedEventArgs e)//强制退出
        {
            Application.Exit();
        }
        public void Table() {
            while(this.dataGridView1.Rows.Count!=0)
            { this.dataGridView1.Rows.RemoveAt(0); }
            string sql = "select * from student";
            fengzhuang dao=new fengzhuang();
            IDataReader dr = dao.read(sql);
            while (dr.Read())
            { string a, b, c, d, e;
            a = dr["id"].ToString();
            b = dr["name"].ToString();
            c = dr["class"].ToString();
            d = dr["birthday"].ToString();
            e = dr["jg"].ToString();
            string[] str = {a, b, c, d, e };
            dataGridView1.Rows.Add(str);
            }
            dr.Close();
        }

        private void 新建学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form21 form21 = new Form21(this);
            form21.ShowDialog();
        }

        private void 删除学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult r = MessageBox.Show("你确定要删除吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (r == DialogResult.OK)
            { string id, name;
            id = dataGridView1.SelectedCells[0].Value.ToString();
            name = dataGridView1.SelectedCells[1].Value.ToString();
            string sql="delete from student where id= '"+id+"'and name='"+name+"'";
            fengzhuang dao=new fengzhuang();
            dao.Excute(sql);
            Table();
            }
        }

        private void 导入学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string[] str = { dataGridView1.SelectedCells[0].Value.ToString(), dataGridView1.SelectedCells[1].Value.ToString(), dataGridView1.SelectedCells[2].Value.ToString(), dataGridView1.SelectedCells[3].Value.ToString(), dataGridView1.SelectedCells[4].Value.ToString() };
            Form21 form21 = new Form21(str,this);
            form21.ShowDialog();
            
            
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)//查询兼职刷新
        {
            Table();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }


        private void 查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                while (this.dataGridView1.Rows.Count != 0)
                { this.dataGridView1.Rows.RemoveAt(0); }
                var i = "";
                i = textBox1.Text.ToString();
                String sql = "select * from student where id='" + i + "' ";
                fengzhuang dao = new fengzhuang();
                IDataReader dr = dao.read(sql);
                while (dr.Read())
                {
                    string a, b, c, d, f;
                    a = dr["id"].ToString();
                    b = dr["name"].ToString();
                    c = dr["class"].ToString();
                    d = dr["birthday"].ToString();
                    f = dr["jg"].ToString();
                    string[] str = { a, b, c, d, f };
                    dataGridView1.Rows.Add(str);
                }
                dr.Close();
            }
            else { MessageBox.Show("请输入查询信息", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); }
        }




    }
}
